#include "stdio.h"
#include "string.h"
#include "math.h"


int count(int a,int b,int c,int d)
{

	int sign,temp;
	int day;

	sign=1;
	if ((b==d)&&(a==c)) return 0;
	if (b>d)
	{
	    sign=0;
	    temp=a;a=c;c=temp;
	    temp=b;b=d;d=temp;
	}

	if (b==d)
	{
		if (a>c)
		{
			sign=0;
			day=a-c;
		}
		else
		{
			day=c-a;
		}
	}
	else
	{
		if (a>c)
		{
			c+=20;
			d--;
		}
		day=(d-b)*20+c-a;
	}
	if (sign==0) day=365-day;
	return day;
}


int main()
{
	int n,i,j,l;
	int a1,a2,b1,b2,c1,c2,d1,d2;
	long int add,tot;
	char s1[21][10]={"","Imix","Ik","Akbal", "Kan", "Chikchan", "Kimi",
			 "Manik","Lamat","Muluk","Ok","Chuen","Eb","Ben",
			 "Ix","Men","Kib","Kaban","Etznab","Kawak","Ajaw"};

	char s2[20][10]={"","Pohp","Wo","Sip","Zotz","Sek","Xul","Yaxkin",
			 "Mol","Chen", "Yax", "Sak", "Keh", "Mak", "Kankin",
			 "Muan", "Pax", "Kayab", "Kumku", "Wayeb"};

	char ins1[10],ins2[10];
	int out[30][6],num;



	scanf("%d",&n);


	for (l=1;l<=n;l++)
	{

		a1=9;b1=20;c1=3;d1=3;
		a2=b2=c2=d2=-1;

		tot=add=0;
		scanf("%d",&a2);
		scanf("%s",ins1);
		scanf("%d",&c2);
		scanf("%s",ins2);
		for (i=1;i<=20;i++)
			if (strcmp(ins1,s1[i])==0)
			{
				b2=i;
				break;
			}
		for (i=1;i<=19;i++)
			if (strcmp(ins2,s2[i])==0)
			{
				d2=i;
				break;
			}

		add=count(c1,d1,c2,d2);
		a1+=add%13;
		if (a1>13) a1-=13;
		b1+=add%20;
		if (b1>20) b1-=20;
		tot+=add;

		if (a2<a1) a2+=13;
		j=a2-a1;
		add=j*365;
		for (i=1;i<=j;i++)
		{
			b1+=5;
			if (b1>20) b1-=20;
		}
		tot+=add;


		if ( (abs(b1-b2))%5!=0 )
		{
			printf("0\n");
		}
		else
		{
			j=0;
			while (b1!=b2)
			{
				b1+=5;
				if (b1>20) b1-=20;
				j++;
			}
			tot+=j*365*13;

			out[1][1]=8;
			for (i=2;i<=5;i++) out[1][i]=0;
			j=tot/7200;
			out[1][2]=j;
			tot-=j*7200;

			j=tot/360;
			out[1][3]=j;
			tot-=j*360;

			j=tot/20;
			out[1][4]=j;
			tot-=j*20;
			out[1][5]=tot;

			num=1;
			while (out[num][1]<=9)
			{
				num++;
				for (i=1;i<=5;i++) out[num][i]=out[num-1][i];
			       out[num][4]-=5;
			       if (out[num][4]<0)
			       {
					out[num][4]+=18;
					out[num][3]--;
			       }
			       out[num][3]-=7;
			       if (out[num][3]<0)
			       {
					out[num][3]+=20;
					out[num][2]--;
			       }
			       out[num][2]+=3;
			       if (out[num][2]>=20)
			       {
					out[num][1]++;
					out[num][2]-=20;
			       }
			}

			num--;
			printf("%d\n",num);
			for (i=1;i<=num;i++)
			{
				for (j=1;j<=4;j++) printf("%d.",out[i][j]);
				printf("%d\n",out[i][5]);
			}

		}



	}

	return 0;

}


/*
name:Calendar of Maya
finish date: 04/9/2
type:模拟题
编程用时：两小时。
调试用时：三小时以上。
problem:算两者之间过渡的天数的函数有一点小错。把同一天之间的过渡天数算成了365
        应该是0天。
*/

